﻿Shader "Custom/HeatFlow"
{
    Properties
    {
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
    }
    SubShader
    {
        CGINCLUDE

        #include "UnityCG.cginc"

        sampler2D _MainTex, _NoiseTex;
		float2 _MainTex_TexelSize;
        float _FlowStrength;
        float _FlowSpeed;

        struct a2v
        {
            float4 vertex : POSITION;
            float2 uv : TEXCOORD0;
        };
        
        struct v2f 
        {
            float4 pos : SV_POSITION;
            float2 uv : TEXCOORD0;
        };

        v2f vert(a2v v)
        {
            v2f i;
            i.pos = UnityObjectToClipPos(v.vertex);
            i.uv = v.uv;
            return i;
        }

        ENDCG

        pass
        {
            CGPROGRAM
            
            #pragma vertex vert
            #pragma fragment frag

            fixed4 frag(v2f i) : SV_TARGET
            {
                float3 offset = tex2D(_NoiseTex, i.uv + _Time.xy * _FlowSpeed).rgb;
                float2 tmpuv = i.uv - offset;
                float2 uv = i.uv - tmpuv * _FlowStrength;
                float3 color = tex2D(_MainTex, uv).rgb;
                return float4(color, 1);
            }
            
            ENDCG
        }
        
    }
    FallBack "Diffuse"
}
